﻿
Public Class classTrades
    Public ID As Integer = 0
    Public Symbol As String = "EURUSD"
    Public Direction As String = "Buy"
    Public Open As Date = Today
    Public Close As Date = Today
    Public TP As Double = 0.0001
    Public SL As Double = 0.0001
    Public picOpen As Bitmap = Nothing
    Public picClose As Bitmap = Nothing
    Public Comment As String = ""
    Public priceEnter As Double = 0.0001
    Public priceClose As Double = 0.0001
    Public Status As String = "Planned"
    Public Online As Boolean = True
    Public lotSize As Double = 0
    Public System As String = ""

    Public ReadOnly Property Results() As Double
        Get
            If priceClose = 0 Then
                Return 0
            End If
            Dim pips As Double = 0
            If Direction = "Buy" Then

                pips = priceClose - priceEnter
            Else
                pips = priceEnter - priceClose
            End If
            If InStr(LCase(Symbol), "yen") Then
                Return Math.Round(pips * 100, 2)
            Else
                Return Math.Round(pips * 10000, 2)
            End If
        End Get
    End Property
    Public ReadOnly Property Ratio() As String
        Get
            If Not (TP = 0 Or SL = 0) Then
                Return "1:" & Math.Round(TP / SL, 2)
            Else
                Return 0
            End If
        End Get
    End Property

    Private Function getText(ByRef strName As String) As String
        Select Case LCase(strName)
            Case "id" : Return ID
            Case "symbol" : Return Symbol
            Case "direction" : Return Direction
            Case "open" : Return Open
            Case "close" : Return Close
            Case "t / p" : Return TP
            Case "s / l" : Return SL
            Case "comment" : Return Comment
            Case "open price" : Return priceEnter
            Case "close price" : Return priceClose
            Case "status" : Return Status
            Case "results(pips)" : Return Results
            Case "ratio" : Return Ratio
            Case "lot size" : Return lotSize
            Case "system" : Return System
            Case Else : Return ""
        End Select
    End Function


    Public Function getLW() As ListViewItem
        Dim ret As New ListViewItem, count As Integer = 0
        For Each z As ToolStripMenuItem In Form1.mnuCollumn.DropDownItems
            If z.Checked Then
                count = count + 1
                If LCase(z.Text) = "results(pips)" Then
                    Dim col As Color = Color.Black
                    If CDbl(getText(z.Text)) < 0 Then col = Color.Red
                    If count > 1 Then
                        ret.SubItems.Add(getText(z.Text)).ForeColor = col
                    Else
                        ret.Text = getText(z.Text)
                        ret.ForeColor = col
                    End If
                Else
                    If count > 1 Then
                        ret.SubItems.Add(getText(z.Text))
                    Else
                        ret.Text = getText(z.Text)
                    End If

                End If
            End If
        Next

        ret.Tag = Me

        'ret.Text = (DatoTid.ToString("dd.MM.yyyy"))
        'ret.SubItems.Add(Tittel)
        'ret.SubItems.Add(Timer)
        ret.Font = New Font("Times New Roman", 10, FontStyle.Regular)
        If Not Online Then ret.BackColor = Color.Pink

        Return (ret)
    End Function


    Public Overrides Function ToString() As String
        Return "todo"
    End Function



End Class
